package com.imooc.mall.controller;

import com.imooc.mall.common.ResultInfo;
import com.imooc.mall.service.IProductDetailService;
import com.imooc.mall.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    IProductService productService;

    @Autowired
    IProductDetailService productDetailService;

    @RequestMapping("/findProduct")
    public ResultInfo findProduct(@RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize,
                                  @RequestParam(required = false) Integer categoryId){
      return   productService.list(categoryId,pageNum,pageSize);

    }

    @RequestMapping("/findProductDetail/{productId}")
    public ResultInfo findProductDetail(@PathVariable Integer productId){
        return   productDetailService.findProductDetail(productId);

    }
}
